﻿package org.hyy.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hyy.dao.CategoryDAO;
import org.hyy.vo.Category;

public class ShowCategory extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		//获取参数
		int menu = Integer.parseInt(request.getParameter("menu"));
		
		//声明
		CategoryDAO categoryDAO = new CategoryDAO();
		List<Category> categories = new ArrayList<Category>();
		categories = categoryDAO.GetCatergories();
		List<Category> showList = null;
		Category category = null;
		
		if(menu == 1){
			showList = new ArrayList<Category>();
			for(int i=0;i<categories.size();i++){
				category = new Category();
				category = categories.get(i);
				if(category.getCno()>10000&&category.getCno()<20000){
					showList.add(category);
				}
			}
			request.setAttribute("menu", menu);
		}
		
		if(menu == 2){
			showList = new ArrayList<Category>();
			for(int i=0;i<categories.size();i++){
				category = new Category();
				category = categories.get(i);
				if(category.getCno()>20000&&category.getCno()<30000){
					showList.add(category);
				}
			}
			request.setAttribute("menu", menu);
		}
		
		if(menu == 3){
			showList = new ArrayList<Category>();
			for(int i=0;i<categories.size();i++){
				category = new Category();
				category = categories.get(i);
				if(category.getCno()>30000&&category.getCno()<40000){
					showList.add(category);
				}
			}
			request.setAttribute("menu", menu);
		}
		
		if(menu == 4){
			showList = new ArrayList<Category>();
			for(int i=0;i<categories.size();i++){
				category = new Category();
				category = categories.get(i);
				if(category.getCno()>40000&&category.getCno()<50000){
					showList.add(category);
				}
			}
			request.setAttribute("menu", menu);
		}
		
		if(menu == 5){
			showList = new ArrayList<Category>();
			for(int i=0;i<categories.size();i++){
				category = new Category();
				category = categories.get(i);
				if(category.getCno()>50000&&category.getCno()<60000){
					showList.add(category);
				}
			}
			request.setAttribute("menu", menu);
		}
		
		if(menu == 6){
			showList = new ArrayList<Category>();
			for(int i=0;i<categories.size();i++){
				category = new Category();
				category = categories.get(i);
				if(category.getCno()>60000&&category.getCno()<70000){
					showList.add(category);
				}
			}
			request.setAttribute("menu", menu);
		}
		
		if(menu == 7){
			showList = new ArrayList<Category>();
			for(int i=0;i<categories.size();i++){
				category = new Category();
				category = categories.get(i);
				if(category.getCno()>70000&&category.getCno()<80000){
					showList.add(category);
				}
			}
			request.setAttribute("menu", menu);
		}
		
		request.setAttribute("categories", showList);
		request.getRequestDispatcher("showCategory.jsp").forward(request, response);
	}

}
